//
//  LSContactsWithinTableViewCell.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2019/6/20.
//  Copyright © 2019 wpkj. All rights reserved.
//

#import "LSContactsWithinTableViewCell.h"
#import "ContactModel.h"

@interface LSContactsWithinTableViewCell ()
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *phoneLabel;
@property (nonatomic, strong) UIImageView *leftImageView;
@property (nonatomic, strong) UILabel *departmentLabel;
@end

@implementation LSContactsWithinTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView addSubview:self.leftImageView];
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.phoneLabel];
        [self.contentView addSubview:self.departmentLabel];
    }
    return self;
}

- (void)setModel:(ContactModel *)model {
    _model = model;
    if ([model.sex isEqualToString:@"女"]) {
        self.leftImageView.image = [UIImage imageNamed:@"famale"];
    } else {
        self.leftImageView.image = [UIImage imageNamed:@"male"];
    }
    self.nameLabel.text = [ValidateUtils validateNull:model.name];
    self.phoneLabel.text = [ValidateUtils validateNull:model.mobile];
    self.departmentLabel.text = [ValidateUtils validateNull:model.department];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    WS
    [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.leftImageView.mas_right).with.offset(15);
        make.bottom.equalTo(weakSelf.contentView.mas_centerY).with.offset(-2);
    }];
    [self.phoneLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.leftImageView.mas_right).with.offset(15);
        make.top.equalTo(weakSelf.contentView.mas_centerY).with.offset(2);
    }];
    [self.departmentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.phoneLabel.mas_right).with.offset(15);
        make.centerY.equalTo(weakSelf.phoneLabel.mas_centerY);
    }];
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:14];
        _nameLabel.textColor = hexColor(333333);
    }
    return _nameLabel;
}

- (UILabel *)phoneLabel {
    if (!_phoneLabel) {
        _phoneLabel = [[UILabel alloc] init];
        _phoneLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:12];
        _phoneLabel.textColor = hexColor(444444);
    }
    return _phoneLabel;
}

- (UILabel *)departmentLabel {
    if (!_departmentLabel) {
        _departmentLabel = [[UILabel alloc] init];
        _departmentLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:12];
        _departmentLabel.textColor = hexColor(5FC82E);
    }
    return _departmentLabel;
}

- (UIImageView *)leftImageView {
    if (!_leftImageView) {
        _leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(12, (LSContactsWithinTableViewCellHeight-leftImageWidth)/2, leftImageWidth, leftImageWidth)];
        _leftImageView.contentMode = UIViewContentModeScaleAspectFit;
        _leftImageView.image = [UIImage imageNamed:@"male"];
    }
    return _leftImageView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
